<?php
/***********************************************************************
 * @package    	IvanEngine
 * @subpackage 	Core
 * @author     	Ivan <ivanzx@msn.com>
 * @created    	2010-05-16
 * @purpose	   	CDatabase is a base abstraction class that allows you to 
 * 				setup any type of database connection via a configuration file.
 ***********************************************************************/
if(defined("IVANENGINE_CORE_DATABASE_DBQUERYRESULT"))
	die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("IVANENGINE_CORE_DATABASE_DBQUERYRESULT", true);

require_once (dirname(__FILE__).'/../STL/Array.php');
require_once (dirname(__FILE__).'/../Exception/Exception.php');

class CDBQueryResult extends CVector
{
	public function __construct(array $result) 
	{
		parent::__construct();
		for ($i = 0; $i < count($result); $i++)
		{
			$temp = new CMap();
			foreach ( $result[$i] as $key => $value )
			{
				$temp->Add($key, $value);
			}
			$this->PushBack($temp);
		}
	}
	
	public function __destruct() 
	{
		parent::__destruct();	
	}
	
	public function Set($where, $val)
	{
		throw new CException("you can not Set() the data of query result of database");
	}
	
	
	public function Erase(CIterator $iter)
	{
		throw new CException("you can not Erase() the data of query result of database");
	}
	
	public function Row($where)
	{
		return $this->Get($where);
	}
	
	public function Col($where)
	{
		$cols	= new CMap();
		$it		= $this->Begin();
		$mIt	= $this->Begin()->Value()->Begin();
		while ($mIt->IsValid())
		{
			$cols->Add($mIt->Key(), new CVector());
			$mIt->Next();
		}
		
		while ($it->IsValid())
		{
			$mIt	= $it->Value()->Begin();
			while ($mIt->IsValid())
			{
				$cols->Get($mIt->Key())->PushBack($mIt->Value());
				$mIt->Next();
			}
			$it->Next();
		}
		return $cols;
	}
}

?>